﻿Imports System
Imports System.Drawing

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class WorkflowRootLayout
        Inherits DefaultWorkflowLayout
        ' Methods
        Public Sub New(ByVal serviceProvider As IServiceProvider)
            MyBase.New(serviceProvider)
        End Sub

        Public Overrides Function MapInCoOrdToLayout(ByVal logicalPoint As Point) As Point
            Dim offset As Size = Me.Offset
            logicalPoint.Offset(-offset.Width, -offset.Height)
            Return logicalPoint
        End Function

        Public Overrides Function MapInRectangleToLayout(ByVal logicalRectangle As Rectangle) As Rectangle
            Dim offset As Size = Me.Offset
            logicalRectangle.X = (logicalRectangle.X - offset.Width)
            logicalRectangle.Y = (logicalRectangle.Y - offset.Height)
            Return logicalRectangle
        End Function

        Public Overrides Function MapOutCoOrdFromLayout(ByVal logicalPoint As Point) As Point
            Dim offset As Size = Me.Offset
            logicalPoint.Offset(offset.Width, offset.Height)
            Return logicalPoint
        End Function

        Public Overrides Function MapOutRectangleFromLayout(ByVal logicalRectangle As Rectangle) As Rectangle
            Dim offset As Size = Me.Offset
            logicalRectangle.X = (logicalRectangle.X + offset.Width)
            logicalRectangle.Y = (logicalRectangle.Y + offset.Height)
            Return logicalRectangle
        End Function


        ' Properties
        Private ReadOnly Property Offset As Size
            Get
                Dim extent As Size = Me.Extent
                Dim size2 As Size = MyBase.parentView.ClientSizeToLogical(MyBase.parentView.ViewPortSize)
                size2.Width = Math.Max(size2.Width, extent.Width)
                size2.Height = Math.Max(size2.Height, extent.Height)
                Return New Size(Math.Max(0, ((size2.Width - extent.Width) / 2)), Math.Max(0, ((size2.Height - extent.Height) / 2)))
            End Get
        End Property

    End Class
End Namespace

